import { createRouter, createWebHashHistory } from "vue-router";
import Home from './../components/Home.vue'

const routes = [
  {
    // 父子路由嵌套
    name: 'home',
    path: '/',
    meta: {
      title: '首页'
    },
    component: Home,//加载首页
    redirect: '/welcome',//重定向到欢迎页 
    children: [
      {
        name: 'welcome',
        path: '/welcome',
        meta: {
          title: '欢迎页'
        },
        component: () => import('./../views/Welcome.vue'),//按需加载首页
      },
      // 子路由共用父路由路径 不加'/' 否则为绝对路径
      {
        name: 'user',
        path: 'system/user',
        meta: {
          title: '用户管理'
        },
        component: () => import('./../views/User.vue'),//按需加载首页
      }
    ]
  },
  {
    name: 'login',
    path: '/login',
    meta: {
      title: '登录'
    },
    component: () => import('../views/Login.vue'),//按需加载登录页
  },
]
const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router